function  countNodes(str){
    const obj=JSON.parse(str)
    var count=0
    for(let i in obj){
        if(i.left==null&&i.right==null){
            count++
        }
        else{
            countNodes(i)
        }
    }
}
var str={ "value": 3,"left": { "value": 9, "left": {"value": 15, "left": null, "right": null }, "right": { "value": 7, "left": null,"right": null } }, "right": { "value": 9, "left": {"value": 15, "left": null, "right": null }, "right": { "value": 7, "left": null,"right": null } }}
countNodes(str)